package com.company.returnsion;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}14:09
 */
public class Maze {
    public static void main(String[] args) {
        //创建迷宫二维数组 默认都为0
        int[][] m = new int[8][8];
        //构建围墙
        for (int i = 0; i < m.length;i++){
            m[0][i] = 1;
            m[7][i] = 1;
            m[i][0] = 1;
            m[i][7] = 1;
        }
        m[3][1] = 1;
        m[3][2] = 1;
        m[1][2] = 1;
        m[4][2] = 1;
        m[4][3] = 1;
        m[5][2] = 1;
        //m[5][6] 为终点
        search(m,1,1);
        for (int i = 0; i < m.length;i++){
            for (int j = 0; j < m[i].length;j++){
                System.out.print(m[i][j]+"\t");
            }
            System.out.println();
        }
    }

    /**
     *
     * @param m 地图坐标
     * @param x 走的横轴
     * @param y 走的竖轴
     * @return
     */
    public static boolean search(int[][] m,int x,int y){
        if (m[6][5] == 2){
            return true;
        }else {
            if (m[x][y] == 0){//当前点还没有走过
                m[x][y] = 2;
                if (search(m,x+1,y)){//向右走
                    return true;
                }else if (search(m,x,y+1)){
                    return true;
                }else if (search(m,x-1,y)){
                    return true;
                }else if (search(m,x,y-1)){
                    return true;
                }else {
                    m[x][y] = 3;//标记死路
                    return false;
                }
            }else {
                return false;
            }
        }
    }



}
